fromFormat Method
Syntax
Arguments
- dateStringstring
A string containing a date.
- dateFormatstring
Defines the format of the dateString parameter. Used to parse the dateString. The date format can use the following directives:
- Directive
- Description
- 0
Format element (causes a time element h, m, or s, to be returned with a leading 0) - Example: 0h:0m:0s
- s
Second
- m
Minute
- h
Hour
- am
12 hour clock with "am" or "pm" suffix
- A
12 hour clock with "A" or "P" suffix
- AM
12 hour clock with "AM" or "PM" suffix
- d
day (one digit) 3
- dd
day spelled out (two digits, 0 pad) 03, 15
- M
month (one digit) 1
- MM
month (two digits, zero pad) 01, 10
- MON
month (three character name, upper case) JAN, FEB
- mon
month (three character name, lower case) jan, feb
- Mon
month (three character name, proper case) Jan, Feb
- MONTH
month (full name, upper case) JANUARY, FEBRUARY
- month
month (full name, lower case) january, february
- Month
month (full name, proper case) e.g. January, February
- y
year (two digits) 99, 03
- yy
year (two digits) 99, 03
- yyyy
year (four digits) 1999, 2003
- switchYearnumber
Used to determine the century when parsing a two digit year (e.g. 1950 or 2050.)
Description
Parses a formatted date string and sets the value of the Date object.
Example
var d = new Date(); // date time format d.fromFormat('12/24/1998 10:00:00 am','MM/dd/yyyy 0h:0m:0s am'); // date w/ switch year (1950)- third parameter d.fromFormat('12/24/10','MM/dd/yy',50);